package br.com.felix.fwt.ui;

import java.io.PrintWriter;

import br.com.felix.fwt.ui.exception.ComponentRenderException;

/**
 * The Class Html is used for you to write random HTML directly.
 * All attributes of BaseComponent are ignored. Only value is used.
 */
public class Html extends BaseComponent{

	
	private static final long serialVersionUID = 8641085868860751142L;

	/**
     * Instantiates a new html.
     */
    public Html(){
        super();
    }
    
    /**
     * Instantiates a new html.
     * 
     * @param html the html to be printed directly in the output.
     */
    public Html(String html){
        super(html);
    }

	/* (non-Javadoc)
	 * @see br.com.felix.fwt.ui.BaseComponent#write(java.io.PrintWriter)
	 */
	@Override
	public void write(PrintWriter out) throws ComponentRenderException {
		if(!authorized()) return;
		out.write("\n");
		String value = getValue();
		switch(getPresentationMode()){
			case DELETED:
				if(style!=null){
					out.write("<span ");
					out.write(style);
					out.write(">");
					out.write("<del>");
					out.write(value);
					out.write("</del>");
					out.write("</span>");
				}
				else{
					out.write("<del>");
					out.write(value);
					out.write("</del>");
				}
				break;
			default:
				if(style!=null){
					out.write("<span ");
					out.write(style);
					out.write(">");
					out.write(value);
					out.write("</span>");
				}
				else{
					out.write(value);
				}
				break;
		}
	}

}
